package a04;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver;
import org.springframework.context.support.GenericApplicationContext;

public class A04 {

    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();

        // ⬇️用原始方法注册三个 bean，这里没有使用扫描自动注册的方式
        context.registerBean("bean1", Bean1.class);
        context.registerBean("bean2", Bean2.class);
        context.registerBean("bean3", Bean3.class);
        context.registerBean("bean4", Bean4.class);

        /**
         * 解析@AutoWired的后置处理器
         */
        //@Autowire要给@Value注入，需要给BeanFactory添加下面这个CandidateResolver
        context.getDefaultListableBeanFactory().setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);

        /**
         * 解析@Resource的后置处理器
         */
        context.registerBean(CommonAnnotationBeanPostProcessor.class); //解析包括@Resource @PostConstruct @PreDestroy

        //会去执行BeanFactory后处理器，添加Bean后处理器，初始化所有的单例
        context.refresh();

    }
}
